﻿
serviceProxy=function(o){this.initialize(o);}
serviceProxy.prototype={initialize:function(o){this.controller=o.controller;var self=this;this.actions=o.actions;if(o.actions){for(var i=0;i<o.actions.length;i++){var _act=o.actions[i];this[_act.name]=_act.func;}}
var _gets=o.gets;var _posts=o.posts;if(_posts){$.each(_posts,function(){var _act=this.action;self[this.name]=function(p,s,e){self._doPost(_act,p,s,e);}});}
if(_gets){$.each(_gets,function(){var _act=this.action;self[this.name]=function(d,s,e){switch(arguments.length){case 0:self._doGet(_act,null,null,null);break;case 1:if($.isFunction(arguments[0]))
self._doGet(_act,null,arguments[0],null);else
self._doGet(_act,arguments[0],null,null);break;case 2:if($.isFunction(arguments[0]))
self._doGet(_act,null,arguments[0],arguments[1]);else
self._doGet(_act,arguments[0],arguments[1],null);break;case 3:self._doGet(_act,d,s,e);break;}}});}
return this;},_doGet:function(_act,_params,_success,_error){var _url=this._resolveUrl(_act),_errHandler=this._errorHandler;if(_params){var _ps=_params,_index=_params["index"],_qs=[];for(var _property in _ps){if(_property.toLowerCase()=="index")
continue;_qs.push(_property+"="+_ps[_property]);}
if(_index)
_url=_url+"/"+_index;if(_qs.length>0)
_url=_url+"?"+_qs.join("&");}
if(_error)
_errHandler=_error;$.ajax({type:"GET",url:_url,success:_success,error:_errHandler});},_doPost:function(_act,_params,_success,_error){var _url=this._resolveUrl(_act);var _errHandler=this._errorHandler;if(_error)
_errHandler=_error;$.ajax({type:"POST",url:_url,data:_params,success:_success,error:_errHandler});},_resolveUrl:function(action){return"/"+this.controller+"/"+action;},_errorHandler:function(XMLHttpRequest,textStatus,errorThrown){var _title=XMLHttpRequest.statusText+"-"+XMLHttpRequest.status;if(textStatus){if(textStatus=="timeout")
uiHelper.showMsg("Ajax Error",portal.res.timeOut);if(textStatus=="error"){var $err=$(XMLHttpRequest.responseText);var $errHeader=$(">h1",$err);var $formatError=$("<div></div>").addClass("ui-state-error ui-corner-all").css({"padding-left":"5px","padding-right":"5px"});if($errHeader.length>0)
$("<p></p>").appendTo($formatError).append($("<span></span>").addClass("ui-icon ui-icon-alert").css({"float":"left","margin-right":"5px"})).end().append($("<strong></strong>").text($errHeader.text()));var $errBody=$(">h2",$err);if($errBody.length>0)
$formatError.append("<p>"+$errBody.text()+"</p>");var htm=$("<div><div>");htm.append($formatError);uiHelper.showMsg(_title,htm.html());}}}}
fileSharingService=function(o){this.initialize(o);}
fileSharingService.prototype={personalDir:null,publicDir:null,download:function(strPath){window.open(this._resolveUrl("GetFile")+"?path="+strPath,"__downloadwin","height=200, width=300, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no");},openFolderDialog:function(strUrl,strPath,fCallback){var _dlg=$("<div></div>").appendTo("body").attr("title","Select file dialog"),_treeview=$("<div></div>").appendTo(_dlg);_treeview.treeview({populatable:true,populateUrl:strUrl,routeData:{path:strPath},selected:function(event,node){window.dialogResult=node.val();}});_dlg.dialog({modal:true,show:"slide",hide:"slide",width:527,position:["left","top"],buttons:{"OK":function(){if($.isFunction(fCallback))
fCallback(window.dialogResult);window.dialogResult=undefined;$(this).dialog("close");$(this).remove();},"Cancel":function(){$(this).dialog("close");}},close:function(){$(this).dialog("destroy");$(this).remove();}});},openFileDialog:function(strUrl,strPath,fCallback){var _dlg=$("<div></div>").appendTo("body").attr("title","Select file dialog"),_folderDropdown=$("<div></div>").appendTo(_dlg),_treeview=$("<div></div>").appendTo(_folderDropdown),_listContent=$("<div></div>").appendTo(_dlg).addClass("ui-listview ui-widget-content").css({"margin-top":"5px","height":"250px"});_treeview.treeview({targetView:_listContent,populatable:true,populateUrl:strUrl,routeData:{path:strPath},selected:function(event,node){_folderDropdown.dropdown("close");_folderDropdown.dropdown("setText",urlHelper.decode(node.val()));},targetloaded:function(event,_target){var _list=$(">div",_target);_list.bind("listviewitemClick",function(event,ui){window.dialogResult=urlHelper.decode(ui.value);});_list.css({"overflow":"scroll","height":"100%","width":"100%"});}});_folderDropdown.dropdown({container:_treeview,autosize:true,defaultText:"Please select a folder first.",minHeight:160});_dlg.dialog({modal:true,show:"slide",hide:"slide",width:300,height:400,buttons:{"OK":function(){if($.isFunction(fCallback))
fCallback(window.dialogResult);window.dialogResult=undefined;$(this).dialog("close");$(this).remove();},"Cancel":function(){$(this).dialog("close");}},close:function(){$(this).dialog("destroy");$(this).remove();}});}}
dynamicUIService=function(o){this.initialize(0);}
dynamicUIService.prototype={showWidgetExplorer:function(){var self=this,_settings=$("#dna_page_settings");var hasWidgetZones=false;if(this.zones){if(this.zones.length)
hasWidgetZones=true;}
if(hasWidgetZones){var _defaultZone=$(self.zones[0]);if(_settings.length==0){_settings=$("<div></div>").prependTo("body").css({height:0,"border-top":"none","padding":"5px"}).attr("id","dna_page_settings");_settings.animate({height:221},1000,function(){if(_settings.children().length==0){uiHelper.blockUI(_settings);$.ajax({url:"/Widget/Explorer",error:function(response){uiHelper.unblockUI(_settings);_settings.html(response.responseText);},success:function(htm){uiHelper.unblockUI(_settings);_settings.html(htm);var _bar=$("<div></div>").appendTo(_settings).addClass("ui-corner-bottom ui-widget-header").css({"height":"35px","padding":"5px","border-top":"none"}),_closeButton=$("<a></a>").appendTo(_bar).actionLink({type:"button",text:"Close",icon:"ui-icon ui-icon-carat-1-n",click:function(){_settings.animate({height:0},1000,function(){_settings.css({display:"none"});});}});$("<a></a>").appendTo(_bar).attr("id","widgetImportButton").actionLink({type:"button",text:"Import",icon:"ui-icon ui-icon-seek-next"});new AjaxUpload("widgetImportButton",{action:"/Widget/Import",name:"importedFile",responseType:"json",data:{"url":document.URL,"zoneID":_defaultZone.attr("id"),pos:0},onSubmit:function(file,extension){uiHelper.blockUI(_settings);},onComplete:function(file,response){uiHelper.unblockUI(_settings);if(response){$nw=$("<div></div>");_defaultZone.prepend($nw);$nw.portlet(response);}}});}});}});}
else
_settings.css({"display":"block"}).animate({height:221},1000);}}}
accountService=function(o){this.initialize(o);}
accountService.prototype={editRoles:function(username){var _d=$("<div title='Edit user roles'><div id='userRolesView'></div></div>");var self=this;_d.dialog({show:"slide",hide:"slide",modal:true,open:function(){self.getUserRoles({"username":username},function(txt){$("#userRolesView").html(txt);_d.dialog("option","position","top");});},buttons:{"Close":function(){_d.dialog('close');_d.remove();}}});}}
$.extend(dynamicUIService.prototype,serviceProxy.prototype);$.extend(fileSharingService.prototype,serviceProxy.prototype);$.extend(accountService.prototype,serviceProxy.prototype);portalApplication=function(){this.initialize();}
portalApplication.prototype={registerService:function(serviceName,serviceOptions,baseService){var _sn=serviceName;if(this[_sn])
return this[_sn];if(baseService){function F(o){this.initialize(o);}
$.extend(F.prototype,baseService.prototype);this[_sn]=new F(serviceOptions);}else
this[_sn]=new serviceProxy(serviceOptions);return this[_sn];},initialize:function(){this.registerService("fileSharing",{controller:"FileSharing",posts:[{name:"getFiles",action:"Files"},{name:"getPaths",action:"Paths"},{name:"remove",action:"Delete"},{name:"createPath",action:"CreatePath"}]},fileSharingService);this.registerService("roles",{controller:"Security",posts:[{name:"addUser",action:"AddUser"},{name:"removeUser",action:"RemoveUser"},{name:"remove",action:"Delete"},{name:"create",action:"Create"},{name:"getUserRoles",action:"UserRoles"}]},null);this.registerService("dynamicUI",{controller:"Widget",posts:[{name:"remove",action:"Delete"},{name:"toggle",action:"Toggle"}]},dynamicUIService);this.registerService("users",{controller:"Account",posts:[{name:"search",action:"Search"}]},accountService);},res:{timeOut:"The ajax call is time out.The remove server is not response.",unknowError:"There is an unknow error dilling the ajax call."}}
$(function(){if(!window.portal)window.portal=new portalApplication();window.urlHelper={encode:function(string){return escape(this._utf8_encode(string));},decode:function(string){return this._utf8_decode(unescape(string));},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c);}
else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}
else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}
return utftext;},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++;}
else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}
else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return string;}}
window.uiHelper={htmlEncode:function(strHtml){if(strHtml)
return strHtml.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');else
return"";},htmlDecode:function(strHtml){if(this.isHtmlEncode(strHtml))
return strHtml.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');return strHtml;},isHtmlEncode:function(strHtml){if(strHtml.search(/&amp;/g)!=-1||strHtml.search(/&lt;/g)!=-1||strHtml.search(/&gt;/g)!=-1)
return true;else
return false;},createDefaultLoader:function(){var _loader=$("<div></div>").appendTo(document.body).addClass("ui-widget-content ui-corner-all ui-state-active").css({padding:10,height:40,width:150});$("<div>Loading...</div>").appendTo(_loader).css({"text-align":"center","display":"block","margin-bottom":"5px"});var pgbar=$("<div></div>").appendTo(_loader).css({height:10});if($.fn.progressbar){pgbar.progressbar();var iid=setInterval(function(){if(pgbar){var _v=pgbar.progressbar("option",'value');if(_v==100)
pgbar.progressbar("option","value",0);else
pgbar.progressbar("option","value",_v+10);}
else
clearInterval(iid);},1000);}
return _loader;},blockUI:function(el,loader){var _loader=null;if(el){if($(el).length==0)
return;if($(".ui-blocking:first",el).length>0)
return;}
else{if(this.blocker)
return;}
if(loader){if($.isFunction(loader))
_loader=loader();else
_loader=loader;}else
_loader=this.createDefaultLoader();var $el=null;var _w=document.documentElement.scrollWidth,_h=document.documentElement.scrollHeight,_l=0,_t=0;if(el){_w=$(el).outerWidth(true);_h=$(el).outerHeight(true);$el=$('<div></div>').appendTo(el).addClass('ui-blocking').css({width:_w,height:_h});var _pos=$(el).position();_l=_pos.left;_t=_pos.top;}
else{$el=$('<div></div>').appendTo(document.body).addClass('ui-blocking').css({width:_w,height:_h});document.body.style.overflow="hidden";}
$el.append($("<div></div>").addClass("ui-widget-overlay").css({width:_w,height:_h,left:_l,top:_t,"position":"absolute"}));_loader.appendTo($el);var _top=($el.outerHeight(true)/2)-(_loader.outerHeight(true)/2);var _left=($el.outerWidth(true)/2)-(_loader.outerWidth(true)/2);if($.browser.safari)
_left=($el.width()/2)-(_loader.width()/2);if(el){_top=_t+_top;_left=_l+_left;}
_loader.css({left:_left,top:_top,position:"absolute","-moz-opacity":"1","filter":"Alpha(Opacity=100)"});if(el==undefined)
this.blocker=$el;},unblockUI:function(el){if(el){var _blocker=$(".ui-blocking:first",el);if(_blocker.length>0){_blocker.fadeOut("normal");_blocker.remove();}}else{if(this.blocker){this.blocker.fadeOut("normal");this.blocker.remove();this.blocker=null;document.body.style.overflow="";}}},rgbToHex:function(str){str=str.replace(/rgb\(|\)/g,"").split(",");str[0]=parseInt(str[0],10).toString(16).toLowerCase();str[1]=parseInt(str[1],10).toString(16).toLowerCase();str[2]=parseInt(str[2],10).toString(16).toLowerCase();str[0]=(str[0].length==1)?'0'+str[0]:str[0];str[1]=(str[1].length==1)?'0'+str[1]:str[1];str[2]=(str[2].length==1)?'0'+str[2]:str[2];return('#'+str.join(""));},inputDialog:function(strTitle,strInputText,fCallback){var _dlg=$("<div></div>").appendTo("body").attr("title",strTitle);$("<div></div>").appendTo(_dlg).text(strInputText);$("<div></div>").appendTo(_dlg).append("<input />");var _input=$("input",_dlg);if($.ui.textbox)_input.textbox({value:""});_dlg.dialog({bgiframe:true,show:"slide",hide:"slide",resizable:false,modal:true,buttons:{"OK":function(){if(_input.val()){if($.isFunction(fCallback))
fCallback(_input.val());$(this).dialog("close");}
else
_input.focus();},"Cancel":function(){$(this).dialog("close");}}});},confirm:function(title,msg,callback){var _d=$("<div title='"+title+"'><p><span class=\"ui-icon ui-icon-alert\" style=\"float:left; margin:0 7px 20px 0;\"></span>"+msg+"</p></div>");_d.dialog({show:"slide",hide:"slide",modal:true,resizable:false,buttons:{"Yes":function(){if(callback)
callback();_d.dialog("close");_d.remove();},"No":function(){_d.dialog("close");_d.remove();}}});},showMsg:function(title,msg){var _d=$("<div title='"+title+"'>"+msg+"</div>");_d.dialog({show:"slide",hide:"slide",modal:true,overlay:{backgroundColor:'#000000',opacity:0.5},buttons:{"OK":function(){_d.dialog("close");_d.remove();}}});},showDlg:function(title,msg){this.showMsg(title,msg);}}});